import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MyHttpServer {
    private int port = 80;
    public void receiving(){
        try{
            //创建socket服务
            ServerSocket serverSocket = new ServerSocket(port);
            //循环接受请求
            while (true){
                //获取连接对象
                Socket socket =serverSocket.accept();
                //获取连接对象的输入流
                InputStream inputStream = socket.getInputStream();
                //创建request
                MyHttpRequest request = new MyHttpRequest(inputStream);
                //解析请求
                request.parse();
                //创建response
                OutputStream outputStream = socket.getOutputStream();
                MyHttpResponse response = new MyHttpResponse(outputStream);
                //进行响应
                response.sendRedirect(request.getUri());
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
